<?php defined('SYSPATH') or die('No direct script access.');

class Library_Page {

	public static function findAll() {
		return ORM::factory('page')
			->join('page')
			->on('page.page_id','=', 'pages.id')
			->where('page.lang','=', I18n::$lang)
			->find_all();
	}

	public static function findByLink($link) {
		return ORM::factory('page')
			->select('page.*')
			->join('page')
			->on('page.page_id','=', 'pages.id')
			->where('pages.link','=',$link)
			->and_where('page.lang','=', I18n::$lang)
			->find();
	}

	public static function findByParent($link) {
		 $parent = ORM::factory('page')
			->where('link','=',$link)
			->find();

		 return ORM::factory('page')
			->select('page.*')
			->join('page')
			->on('page.page_id','=', 'pages.id')
			->and_where('pages.id','=', $parent->parent_id)
			->and_where('page.lang','=', I18n::$lang)
			->find();
	}
}
?>
